﻿

Imports System.Object
Imports VSModel
Imports Cls_Common
Imports System.IO
Imports System.Data
Partial Class Control_Raovat_Detail
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "duyjs", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "duyjs", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If

            If (Not Page.RouteData.Values("Id") Is Nothing) Then

                hidID.Value = Page.RouteData.Values("Id")
                ShowThongTinCoBan()
                ShowTienNghi()
                ShowThongSoKyThuat()
                ShowAnToan()
                ShowData()

            End If
        End If
    End Sub

    Protected Sub ShowData()
        Using data As New VSEntities
            Dim intRaoVat As Integer = CInt(hidID.Value.Trim)
            Dim p As uspRaovatSelect_Result = data.uspRaovatSelect(intRaoVat).FirstOrDefault
            If Not p Is Nothing Then
                ltrTitle.Text = IIf(IsNothing(p.Title) = True, "", p.Title) & " <span>" & CType(p.OriginalPrice, Double).ToString("#,##") & " tr </span>"

                'lblDescription.Text = IIf(IsNothing(p.Description) = True, "", p.Description)
                hidImagePath.Text = IIf(IsNothing(p.ImagePreview) = True, "", p.ImagePreview)
                'imgUpload.ImageUrl = IIf(IsNothing(p.ImagePreview) = True, "", p.ImagePreview)
                'lblGia.Text = IIf(IsNothing(p.OriginalPrice) = True, "", p.OriginalPrice)
                lblHoTen.Text = p.HoTen.Trim
                ltrDiachi.Text = p.DiaChi & " " & p.TinhTP
                ltrDienThoai.Text = p.Phone
                If Not p.PhoneOther Is Nothing Then
                    ltrDienThoai.Text = ltrDienThoai.Text & p.PhoneOther
                End If

                'lblTP.Text = p.TinhTP

                'Dim strImage As String = ""
                Dim t = (From a In data.RaovaImages Where a.RaoVatId = p.RaovatId Select a.RaoVatId, a.ImageURL, a.Description).ToList
                rptShow.DataSource = t
                rptShow.DataBind()

            End If
        End Using
    End Sub

    Protected Sub ShowThongTinCoBan()
        Using data As New VSEntities
            Dim p As uspThongsocobanSelect_Result = data.uspThongsocobanSelect(hidID.Value).FirstOrDefault
            If Not p Is Nothing Then
                'lbl = IIf(IsNothing(p.XuatXu) = True, "", p.XuatXu)
                lblTinhTrang.Text = IIf(IsNothing(p.TinhTrang) = True, "", p.TinhTrang)
                lblDongXe.Text = IIf(IsNothing(p.DongXe) = True, "", p.DongXe)
                lblSoKm.Text = IIf(IsNothing(p.SoKLMDaDi) = True, "", p.SoKLMDaDi)
                lblMauNgoaiThat.Text = IIf(IsNothing(p.MauNgoaiThat) = True, "", p.MauNgoaiThat)
                lblMauNoiThat.Text = IIf(IsNothing(p.MauNoiThat) = True, "", p.MauNoiThat)
                lblSocua.Text = IIf(IsNothing(p.SoCua) = True, "", p.SoCua)
                lblSochongoi.Text = IIf(IsNothing(p.SoChoNgoi) = True, "", p.SoChoNgoi.ToString)
                lblNhienLieu.Text = IIf(IsNothing(p.NhienLieu) = True, "", p.NhienLieu)
                lblHeThongNhienLieu.Text = IIf(IsNothing(p.HeThongNhienLieu) = True, "", p.HeThongNhienLieu)
                lblHopSo.Text = IIf(IsNothing(p.HopSo) = True, "", p.HopSo)
                lblDanDong.Text = IIf(IsNothing(p.DanDong) = True, "", p.DanDong)
                lblTieuthunhienlieu.Text = IIf(IsNothing(p.TieuThuNhienLieu) = True, "", p.TieuThuNhienLieu)
                lblThietBiKhacCoBan.Text = IIf(IsNothing(p.Description) = True, "", p.Description)
                lblHang.Text = IIf(IsNothing(p.HangCheTao) = True, "", p.HangCheTao)
                lblDoixe.Text = IIf(IsNothing(p.DoiXe) = True, "", p.DoiXe)
                lblNamsanxuat.Text = IIf(IsNothing(p.NamSanXuat) = True, "", p.NamSanXuat)


            End If
        End Using
    End Sub

    Protected Sub ShowAnToan()
        Using data As New VSEntities
            Dim p As AnToan = (From q In data.AnToans Where q.RaoVatId = hidID.Value Select q).FirstOrDefault
            If Not p Is Nothing Then
                rptTuiKhiNguoiLai.Checked = IIf(IsNothing(p.TuiKhiNguoiLai) = True, False, p.TuiKhiNguoiLai)
                rptTuiKhiTruoc.Checked = IIf(IsNothing(p.TuiKhiTruoc) = True, False, p.TuiKhiTruoc)
                rptTuiKhisau.Checked = IIf(IsNothing(p.TuiKhiSau) = True, False, p.TuiKhiSau)
                rptHaiBenGhe.Checked = IIf(IsNothing(p.TuiKhiHaiBenGhe) = True, False, p.TuiKhiHaiBenGhe)
                rptABS.Checked = IIf(IsNothing(p.PhanhABS) = True, False, p.PhanhABS)
                ' rpt.Checked = IIf(IsNothing(p.PhanBoLucABD) = True, False, p.PhanBoLucABD)
                rptEBA.Checked = IIf(IsNothing(p.TroLucPhanhEBA) = True, False, p.TroLucPhanhEBA)
                rptESB.Checked = IIf(IsNothing(p.CanBangDienTuESP) = True, False, p.CanBangDienTuESP)
                rptDKHanhTrinh.Checked = IIf(IsNothing(p.DieuKhienHanhTrinh) = True, False, p.DieuKhienHanhTrinh)
                rptCanhBaoLui.Checked = IIf(IsNothing(p.HoTroCanhBaoLui) = True, False, p.HoTroCanhBaoLui)
                rptKiemSoatTruot.Checked = IIf(IsNothing(p.KiemSoatTruot) = True, False, p.KiemSoatTruot)
                rptChotAntoan.Checked = IIf(IsNothing(p.ChotCuaAnToan) = True, False, p.ChotCuaAnToan)
                rptKhoaCuaTuDong.Checked = IIf(IsNothing(p.KhoaCuaTuDong) = True, False, p.KhoaCuaTuDong)
                rptKhoaCuaDKTuXa.Checked = IIf(IsNothing(p.KhoaCuaDKTuXa) = True, False, p.KhoaCuaDKTuXa)
                rptKhoaDongCo.Checked = IIf(IsNothing(p.KhoaDongCo) = True, False, p.KhoaDongCo)
                rptChongTrom.Checked = IIf(IsNothing(p.HTBaoNgoaiVi) = True, False, p.HTBaoNgoaiVi)
                rptDenSuongMu.Checked = IIf(IsNothing(p.DenSuongMu) = True, False, p.DenSuongMu)
                rptThatDayAnToan.Checked = IIf(IsNothing(p.DenDayAnToan) = True, False, p.DenDayAnToan)
                rptDenPhu.Checked = IIf(IsNothing(p.DenPhanhPhu3) = True, False, p.DenPhanhPhu3)

            End If
        End Using
    End Sub

    Protected Sub ShowTienNghi()
        Using data As New VSEntities
            Dim p As TienNghi = (From q In data.TienNghis Where q.RoaVatId = hidID.Value Select q).FirstOrDefault
            If Not p Is Nothing Then
                rptThietBiDinhVi.Checked = IIf(IsNothing(p.ThietBiDinhVi) = True, False, p.ThietBiDinhVi)
                rptCuaSoNoc.Checked = IIf(IsNothing(p.CuaSoNoc) = True, False, p.CuaSoNoc)
                rptKinhChinhDien.Checked = IIf(IsNothing(p.KinhChinhDien) = True, False, p.KinhChinhDien)
                rptTayLaiTroLuc.Checked = IIf(IsNothing(p.TayLaiTroLuc) = True, False, p.TayLaiTroLuc)
                lblGheChatLieu.Text = IIf(IsNothing(p.GheChatLieuTienNghi) = True, False, p.GheChatLieuTienNghi)
                rptDieuHoaTruoc.Checked = IIf(IsNothing(p.DieuHoaTruoc) = True, False, p.DieuHoaTruoc)
                rptDieuHoaSau.Checked = IIf(IsNothing(p.DieuHoaSau) = True, False, p.DieuHoaSau)
                rptHoTroXeTuDong.Checked = IIf(IsNothing(p.HoTroXeTuDong) = True, False, p.HoTroXeTuDong)
                rptSaykinhsau.Checked = IIf(IsNothing(p.SayKinhSau) = True, False, p.SayKinhSau)
                rptQuatKinhSau.Checked = IIf(IsNothing(p.QuatKinhPhiaSau) = True, False, p.QuatKinhPhiaSau)
                rptKinhMau.Checked = IIf(IsNothing(p.KinhMau) = True, False, p.KinhMau)
                rptLCD.Checked = IIf(IsNothing(p.ManHinhLCD) = True, False, p.ManHinhLCD)
                rptGiaiTri.Checked = IIf(IsNothing(p.ThietBiGiaiTri) = True, False, p.ThietBiGiaiTri)
                lblThietBiKhacTienNghi.Text = IIf(IsNothing(p.ThietBiKhac) = True, "", p.ThietBiKhac)

            End If
        End Using
    End Sub

    Protected Sub ShowThongSoKyThuat()
        Using data As New VSEntities
            Dim p As uspThongsokythuatSelect_Result = data.uspThongsokythuatSelect(hidID.Value).FirstOrDefault
            If Not p Is Nothing Then
                lblDaiRongCao.Text = IIf(IsNothing(p.DaiRongCao) = True, "", p.DaiRongCao)
                lblChieudaicoso.Text = IIf(IsNothing(p.ChieuDaiCoSo) = True, "", p.ChieuDaiCoSo)
                lblChieurongcoso.Text = IIf(IsNothing(p.ChieuRongCoSo) = True, "", p.ChieuRongCoSo)
                lblTrongluongkhongtai.Text = IIf(IsNothing(p.TrongLuongKhongTai) = True, "", p.TrongLuongKhongTai)
                lblDungtichbinhnhienlieu.Text = IIf(IsNothing(p.DungTichBinhNhienLieu) = True, "", p.DungTichBinhNhienLieu)
                lblDongCo.Text = IIf(IsNothing(p.DongCo) = True, "", p.DongCo)
                lblKieuDongCo.Text = IIf(IsNothing(p.KieuDongCo) = True, "", p.KieuDongCo)
                lblDungtichxilanh.Text = IIf(IsNothing(p.DungTichXiLanh) = True, "", p.DungTichXiLanh)
                lblPhanh.Text = IIf(IsNothing(p.Phanh) = True, "", p.Phanh)
                lblGiamSoc.Text = IIf(IsNothing(p.GiamSoc) = True, "", p.GiamSoc)
                lblLopXe.Text = IIf(IsNothing(p.LopXe) = True, "", p.LopXe)
                lblVanhMam.Text = IIf(IsNothing(p.VanhMam) = True, "", p.VanhMam)
                lblThietBiKhacKyThuat.Text = IIf(IsNothing(p.ThongSoKhac) = True, "", p.ThongSoKhac)
            End If
        End Using
    End Sub

    Protected Sub rptShow_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptShow.ItemDataBound
        Dim row = CType(e.Item.DataItem, Object)
        Dim img As Image = CType(e.Item.FindControl("img"), Image)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)

        hplTitle.NavigateUrl = CookedImageURL("225-310", row.ImageURL.ToString)
        img.ImageUrl = row.ImageURL.ToString
        img.ToolTip = row.Description
        img.CssClass = "image" & e.Item.ItemIndex.ToString
        img.AlternateText = row.Description
    End Sub

    'Protected Sub rptRelation_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptRelation.ItemDataBound
    '    Dim row = CType(e.Item.DataItem, Object)
    '    Dim img As Image = CType(e.Item.FindControl("img"), Image)
    '    Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
    '    Dim ltrPrice As Literal = CType(e.Item.FindControl("ltrPrice"), Literal)

    '    ltrPrice.Text = FormatNumber(row.OriginalPrice.ToString) & ""
    '    img.ImageUrl = CookedImageURL("140-120", row.ImagePreview.ToString)
    '    hplTitle.Text = row.Title
    '    hplTitle.NavigateUrl = MainDomain & "rao-vat-chi-tiet/" & row.QueryString & "-" & row.RaovatId.ToString & ".html"

    'End Sub

End Class
